package com.berry_med.handsetmonitor.volleyFramework;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.StrictMode;

import com.andware.volley.RequestQueue;

import java.util.LinkedList;
import java.util.List;


/**
 * Created by ishishuji on 14/12/5.
 */
public class VOAFramework {

    private static VOAFramework _instance;

    public static class Config {
        public static final boolean DEVELOPER_MODE = false;
    }

    private List< Activity > activityList = new LinkedList< Activity > ();


    public void finishAllStack () {

        for ( Activity activity : activityList ) {
            activity.finish ();
        }

        resumeActivityList ();

    }

    public void addActivityToStack ( Activity activity ) {
        activityList.add ( activity );
    }

    public void resumeActivityList () {
        activityList.clear ();
    }

    public static RequestQueue getRequestQueue () {
        return MyVolley.getRequestQueue ();
    }

    public static VOAFramework getInstance () {
        if ( _instance == null ) {
            _instance = new VOAFramework ();
        }
        return _instance;
    }

    @TargetApi (VERSION_CODES.GINGERBREAD)
    public void init ( Context context ) {
        if ( Config.DEVELOPER_MODE && Build.VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD ) {
            StrictMode.setThreadPolicy ( new StrictMode.ThreadPolicy.Builder ().detectAll ().penaltyDialog ().build () );
            StrictMode.setVmPolicy ( new StrictMode.VmPolicy.Builder ().detectAll ().penaltyDeath ().build () );
        }

        MyVolley.init ( context );

    }


}
